package com.atguigu.springcloud.cloudsentinelgatewaydevelop.controller;

import com.atguigu.springcloud.cloudsentinelgatewaydevelop.bean.dto.SentinelAuthorityRuleDTO;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.service.AuthorityRuleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 授权规则控制器
 *
 * @author BugFree Jin
 * @version 1.0
 * @since 2022/3/2 9:28
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/authorityrule")
public class AuthorityRuleController {

    private final AuthorityRuleService authorityRuleService;

    @PostMapping("/save")
    public Mono<Integer> save(@RequestBody SentinelAuthorityRuleDTO sentinelAuthorityRuleDTO) {
        return authorityRuleService.save(sentinelAuthorityRuleDTO);
    }

    @GetMapping("/find/{id}")
    public Mono<SentinelAuthorityRuleDTO> getById(@PathVariable("id") Long id) {
        return authorityRuleService.findById(id);
    }

    @GetMapping("/finds/{applicationName}")
    Mono<List<SentinelAuthorityRuleDTO>> findByApplicationName(@PathVariable("applicationName") String applicationName) {
        return authorityRuleService.findByApplicationName(applicationName).collectList();
    }

    @DeleteMapping("/delete/{id}")
    Mono<Integer> deleteById(@PathVariable Long id) {
        return authorityRuleService.deleteById(id);
    }

    @DeleteMapping("/deletes/{applicationName}")
    Mono<Integer> deleteByAyApplicationName(@PathVariable("applicationName") String applicationName) {
        return authorityRuleService.deleteByAyApplicationName(applicationName);
    }

}
